﻿<Window
    x:Class="PerformanceDude.MSBuildShellExtension.Loggers.ErrorListLogger.BuildOutputDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:common="clr-namespace:PerformanceDude.MSBuildShellExtension.Common;assembly=Common"
    xmlns:self="clr-namespace:PerformanceDude.MSBuildShellExtension.Loggers.ErrorListLogger"
    mc:Ignorable="d" 
    Title="Build Output"
    ResizeMode="CanResizeWithGrip"
    WindowStyle="ThreeDBorderWindow"
    Closing="Window_Closing"
    d:DesignHeight="300"
    d:DesignWidth="600">
    <Window.Resources>
        <self:LevelToImageConverter x:Key="LevelToImageConverter" />
        <Style TargetType="ToggleButton" x:Key="LevelButton">
            <Setter Property="ClickMode" Value="Press" />
            <Setter Property="MinWidth" Value="90" />
            <Setter Property="Margin" Value="2" />
        </Style>
        <Style TargetType="Image" x:Key="LevelImage">
            <Setter Property="Margin" Value="0,0,5,0" />
        </Style>
    </Window.Resources>
    <Grid HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
            <!-- TabControl -->
            <RowDefinition Height="*" />
            <!-- Status Bar -->
            <RowDefinition Height="25" />
        </Grid.RowDefinitions>
        <TabControl Grid.Row="0" TabStripPlacement="Bottom">
            <TabItem Header="Error List">
                <Grid HorizontalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <!-- Errors, Warnings, and Messages Toggle Buttons -->
                        <RowDefinition Height="30" />
                        <!-- DataGrid -->
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <StackPanel Orientation="Horizontal" Grid.Row="0">
                        <ToggleButton x:Name="btnErrors" Checked="btnErrors_Checked" Unchecked="btnErrors_Checked" Style="{StaticResource LevelButton}">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="/MSBuildShellExtensionLogger;component/Resources/Symbols-Error-16x16.png" Style="{StaticResource LevelImage}" ToolTip="Error" />
                                <TextBlock x:Name="tbErrors">0 Errors</TextBlock>
                            </StackPanel>
                        </ToggleButton>
                        <ToggleButton x:Name="btnWarnings" Checked="btnWarnings_Checked" Unchecked="btnWarnings_Checked" Style="{StaticResource LevelButton}">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="/MSBuildShellExtensionLogger;component/Resources/Symbols-Warning-16x16.png" Style="{StaticResource LevelImage}" ToolTip="Warning" />
                                <TextBlock x:Name="tbWarnings">0 Warnings</TextBlock>
                            </StackPanel>
                        </ToggleButton>
                        <ToggleButton x:Name="btnMessages" Checked="btnMessages_Checked" Unchecked="btnMessages_Checked" Style="{StaticResource LevelButton}">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="/MSBuildShellExtensionLogger;component/Resources/Symbols-Info-16x16.png" Style="{StaticResource LevelImage}" ToolTip="Message" />
                                <TextBlock x:Name="tbMessages">0 Messages</TextBlock>
                            </StackPanel>
                        </ToggleButton>
                    </StackPanel>
                    <dg:DataGrid Grid.Row="1" x:Name="dgOutputMessages" AutoGenerateColumns="False" IsReadOnly="True" MouseDoubleClick="dgOutputMessages_MouseDoubleClick" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray">
                        <dg:DataGrid.Columns>
                            <dg:DataGridTemplateColumn CanUserResize="False">
                                <dg:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ContentControl Content="{Binding Level, Converter={StaticResource LevelToImageConverter}}" VerticalAlignment="Top" />
                                    </DataTemplate>
                                </dg:DataGridTemplateColumn.CellTemplate>
                            </dg:DataGridTemplateColumn>
                            <dg:DataGridTemplateColumn CanUserResize="False">
                                <dg:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Index}" TextWrapping="NoWrap"/>
                                    </DataTemplate>
                                </dg:DataGridTemplateColumn.CellTemplate>
                            </dg:DataGridTemplateColumn>
                            <dg:DataGridTemplateColumn Header="Description" Width="5*">
                                <dg:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
                                    </DataTemplate>
                                </dg:DataGridTemplateColumn.CellTemplate>
                            </dg:DataGridTemplateColumn>
                            <dg:DataGridTextColumn Header="File" Binding="{Binding File}" Width="2*" />
                            <dg:DataGridTextColumn Header="Line" Binding="{Binding Line}" Width="2*" />
                            <dg:DataGridTextColumn Header="Column" Binding="{Binding Column}" Width="1*" />
                            <dg:DataGridTemplateColumn Header="Project" Width="2*">
                                <dg:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Project}" TextWrapping="Wrap"/>
                                    </DataTemplate>
                                </dg:DataGridTemplateColumn.CellTemplate>
                            </dg:DataGridTemplateColumn>
                        </dg:DataGrid.Columns>
                        <dg:DataGrid.RowStyle>
                            <Style TargetType="{x:Type dg:DataGridRow}">
                                <EventSetter Event="Control.RequestBringIntoView" Handler="dgOutputMessages_RequestBringIntoView"  />
                            </Style>
                        </dg:DataGrid.RowStyle>
                    </dg:DataGrid>
                </Grid>
            </TabItem>
            <TabItem Header="Output">
                <TextBox x:Name="tbOutput" IsReadOnly="True" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" />
            </TabItem>
        </TabControl>
        <StatusBar Grid.Row="2">
            <StatusBarItem>
                <TextBlock x:Name="tbStatusBar" Text="Ready" />
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
